package com.security.user.config;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.time.Instant;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author yanggld
 * @Date 2020/3/9-14:54
 */
@RestControllerAdvice
public class ErrorHandler {

    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(Exception.class)
    public Map<String,Object> handle(Exception ex){
        ex.printStackTrace();
        HashMap<String, Object> info = new HashMap<>();
        info.put("message",ex.getMessage());
        info.put("time", Instant.now().toString());
        return info;
    }
}
